<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\Controller;

use App\JsonRpc\MomentServiceInterface;
use Hyperf\Context\ApplicationContext;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;

#[Controller]
class MomentController extends AbstractController
{
    #[RequestMapping(path: '/moment/list',methods: ['GET'])]
    public function list(): array
    {
        $page = (int)$this->request->input('page', 1);
        $pageSize = (int)$this->request->input('pageSize', 10);
        $type = (int)$this->request->input('type', 1);
        $server = ApplicationContext::getContainer()->get(MomentServiceInterface::class);
        return $server->list($page, $pageSize, $type);
    }

    #[RequestMapping(path: '/moment/create',methods: ['POST'])]
    public function create(): array
    {
        $data = $this->request->inputs(['title', 'content', 'photo']);
        $server = ApplicationContext::getContainer()->get(MomentServiceInterface::class);
        return $server->create($data);
    }

    #[RequestMapping(path: '/moment/delete/{id}',methods: ['DELETE'])]
    public function delete(int $id): array
    {
        $server = ApplicationContext::getContainer()->get(MomentServiceInterface::class);
        return $server->delete($id);
    }

    #[RequestMapping(path: '/moment/update/{id}',methods: ['PUT'])]
    public function update(int $id): array
    {
        $update = $this->request->all();
        $server = ApplicationContext::getContainer()->get(MomentServiceInterface::class);
        return $server->update($id, $update);

    }

    #[RequestMapping(path: '/moment/detail/{id}',methods: ['GET'])]
    public function detail(int $id): array
    {
        $server = ApplicationContext::getContainer()->get(MomentServiceInterface::class);
        return $server->detail($id);
    }
}
